package com.spring.aop.test;

import com.spring.aop.config.AppConfig;
import com.spring.aop.service.HelloPeople;
import com.spring.aop.service.IPeople;
import com.spring.aop.service.People;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 每一行代码，都是改变世界的力量
 *
 * @author 郭帅
 * @date 2021/11/1 11:21 下午
 */
public class Main {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext context =
                new AnnotationConfigApplicationContext(AppConfig.class);

        IPeople people = (IPeople) context.getBean("people");
        people.say();

        BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(HelloPeople.class, () -> new HelloPeople());
        context.registerBeanDefinition("helloPenple", beanBuilder.getBeanDefinition());

        IPeople helloPenple = (IPeople) context.getBean("helloPenple");
        helloPenple.say();


    }

}
